<?php 
class App_User_Pager_AdminUser extends Main_Pager
{
	/**
	 * @var array
	 */
	protected $_fields = array(
		'id'   => array('simpleSearch' => true, 'sql' => 'user.id'),
		'login' => array('simpleSearch' => true, 'sql' => 'user.login'),
		'f_active' => array('simpleSearch' => false, 'sql' => 'user.f_active'),
		'role_name' => array('simpleSearch' => true, 'sql' => 'role_i18n.name'),	
	);
	
	/**
	 * @return void
	 */
	protected function _init()
	{
		$this->_config['base'] = "
			SELECT 
				user.id
				, user.login
				, user.f_active
				, role_i18n.name role_name 	
			FROM
				user 
			INNER JOIN
				role 
				ON
					(user.role_id = role.id)
			INNER JOIN
				role_i18n 
				ON
					(role.id=role_i18n.role_id AND role_i18n.lang_id={$this->_langId})
			WHERE true		
		";
		
		
				
		$this->_config['count'] = "
			SELECT 
				COUNT(user.id)
			FROM
				user 
			INNER JOIN
				role 
				ON
					(user.role_id = role.id)
			INNER JOIN
				role_i18n 
				ON
					(role.id=role_i18n.role_id AND role_i18n.lang_id={$this->_langId})
			WHERE true	
		";		

		$this->_service = new App_User_Service_User();
						
		parent::_init();			
	}
	
	/**
	 * @param int|string $primary
	 * @return bool
	 */
	protected function _deleteItem($primary) 
	{
		return $this->_service->deleteItem($primary);
	}
}


